<template>
	<view class="switch">
		<view class="list">
			<view class="li" v-for="(item, index) in userList" :key="index">
				<!-- <image src="../../static/card/add.png" mode="" class="img"></image> -->
				<view class="name1" v-if="item.ismaster == 1">{{ item.account }}</view>
				<view class="name" v-else>{{ item.account }}</view>
				<view class="btn1"></view>
				<!-- v-if="item.ismaster != 1" @click="jump('/pages/setting/amend?id=4')">解绑换手机号 -->
				<block v-if="item.status == 1"><view class="btns">当前账号</view></block>

				<block v-else>
					<view class="btn" v-if="item.ismaster == 1" @click="cut(item.account)">切换主账号</view>
					<view class="btn" v-else @click="cut(item.account)">切换子账号</view>
				</block>
			</view>
		</view>

		<!-- <view class="info">
			<view class="button" @click="insert" v-if="isinsert == 1">添加子账号</view>
		</view> -->
	</view>
</template>

<script>
import service from '@/store/service.js';
export default {
	data() {
		return {
			accid: 0,
			userList: [],
			isinsert: 1,
			status: 1
		};
	},
	onShow() {
		this.getAccount();
	},
	methods: {
		jump(url) {
			uni.navigateTo({
				url: url
			});
		},
		getAccount() {
			let that = this;
			that.$http.get(service.api.user.obtain).then(function(res) {
				if (res.code === 1) {
					that.userList = res.data;
					console.log(res.data);
				} else {
					that.$api.msg(res.info);
				}
			});
		},
		insert() {
			uni.navigateTo({
				url: '/pages/setting/insert'
			});
		},
		cut(account) {
			let that = this;
			that.$http
				.post(service.api.user.switcher, {
					account: account
				})
				.then(res => {
					that.$api.msg(res.info);
					uni.setStorageSync('token', res.data.token);
					uni.setStorageSync('authorization', 'Bearer ' + res.data.token);
					if (res.code === 1) {
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							});
						}, 1500);
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
@import '../../common/uni.css';
page {
	background: #f2f2f2;
}

.list {
	padding-bottom: 80upx;
}

.li {
	width: 100%;
	display: flex;
	height: 100upx;
	background: #ffffff;
	border-bottom: 2upx solid #f2f2f2;
}
.img {
	width: 80upx;
	height: 80upx;
	margin: 10upx;
	border-radius: 40upx;
}
.name,
.name1 {
	line-height: 100upx;
	padding-left: 20upx;
	width: calc(100% - 400upx);
}
.name1 {
	width: calc(100% - 200upx);
}
.btn,
.btns {
	width: 170upx;
	height: 52upx;
	text-align: center;
	line-height: 52upx;
	margin: 24upx 20upx;
	border-radius: 26upx;
}

.btn {
	min-width: 200upx;
	color: #ffffff;
	background: #f8124a;
}
.btn1 {
	width: 210upx;
	height: 52upx;
	text-align: center;
	line-height: 52upx;
	margin: 24upx 20upx;
	border-radius: 26upx;
	color: #ffffff;
	/* background: #f8124a; */
}
.button {
	width: 630upx;
	height: 80upx;
	line-height: 80upx;
	background: #f81149;
	border-radius: 40upx;
	margin: 0 auto 40upx;
	text-align: center;
	color: #fff;
	font-size: 32upx;
}
</style>
